package com.ztzh.temteam.example;

import com.ztzh.temteam.example.dto.UploadResp;
import com.ztzh.temteam.utils.ChatDocUtil;
import org.springframework.stereotype.Component;

import java.net.URISyntaxException;

/**
 * ChatMessage
 *
 * @author yiyong
 **/
@Component
public class Main {
    public static final String uploadUrl = "https://chatdoc.xfyun.cn/openapi/v1/file/upload";
    public static final String fileStatusUrl = "https://chatdoc.xfyun.cn/openapi/v1/file/status";
    public static final String chatUrl = "wss://chatdoc.xfyun.cn/openapi/chat";
    public static final String appId = "714037a7";
    public static final String secret = "MWQ5MzY5YzU4NTY0MTdhNDgyMDMwNzM2";

    public static String start(String file) {
        ChatDocUtil chatDocUtil = new ChatDocUtil();
        // 1、上传
        UploadResp uploadResp = chatDocUtil.upload(file, uploadUrl, appId, secret);
        System.out.println("请求sid=" + uploadResp.getSid());
        System.out.println("文件id=" + uploadResp.getData().getFileId());

        // 2、问答，上传文件状态为vectored时才可以问答，文件状态可以调用【文档状态查询】接口查询
        String fileId = uploadResp.getData().getFileId();
        String question = "文档是啥内容哦";
//        try {
//            chatDocUtil.chat(chatUrl, fileId, question, appId, secret);
//        } catch (URISyntaxException e) {
//            e.printStackTrace();
//        }
        return uploadResp.getData().getFileId();
    }

    public static void chat(String quesson, String fileId) {
        ChatDocUtil chatDocUtil = new ChatDocUtil();

        // 2、问答，上传文件状态为vectored时才可以问答，文件状态可以调用【文档状态查询】接口查询
        // String fileId = uploadResp.getData().getFileId();
        String question = quesson;
        try {
            chatDocUtil.chat(chatUrl, fileId, question, appId, secret);
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
    }
}